package br.os.view;

import java.io.IOException;

import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.animations.CommonTransitions;

/**
 * 
 * @author Arthur
 */
public class ExitDialog extends Dialog {

	private TextArea message;
	private Image exitIcon;
	private Label exitLabel;

	public ExitDialog() {
		this.setDialogType(Dialog.TYPE_CONFIRMATION);
		createImages();
		configureDialogStyles();
		configureMessage();
		configureLabel();
		configureTransitions();
		addComponents();
	}

	public ExitDialog(String title) {
		super(title);

	}

	private void addComponents() {
		this.addComponent(exitLabel);
		this.addComponent(message);
	}

	private void configureDialogStyles() {

		this.getStyle().setBgTransparency(50);
		this.getComponentAt(0).getStyle().setBgTransparency(200);
		this.getComponentAt(0).getStyle().setBgColor(0xE70303, true);
		this.getComponentAt(1).getStyle().setBgTransparency(200);
		this.getComponentAt(1).getStyle().setBgColor(0x757575, true);
	}

	private void configureLabel() {
		exitLabel = new Label();
		exitLabel.setTextPosition(Component.BOTTOM);
		exitLabel.setIcon(exitIcon);

		exitLabel.getStyle().setMargin(3, 2, exitLabel.getPreferredW() / 2,
				exitLabel.getPreferredW() / 2);
	}

	private void configureMessage() {
		message = new TextArea();
		message.setText("Você tem certeza que deseja sair?");
		message.setAlignment(Component.LEFT);
		message.setEnabled(false);
		message.getStyle().setMargin(1, 0, 0, 0);
		configureMessageFont();
	}

	private void configureMessageFont() {
		/**Não implementado*/
	}

	private void configureTransitions() {
		this.setTransitionInAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_VERTICAL, true, 650, true));
		this.setTransitionOutAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_VERTICAL, true, 650, true));
	}

	private void createImages() {
		try {
			exitIcon = Image.createImage("/icons/dialogError.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
